<template>
  <el-dialog :visible.sync="dialog" title="订单审核">
    <el-form ref="auditForm" :model="auditForm" :rules="auditRules" label-width="100px">
      <el-form-item label="订单号：" prop="orderSn">
        {{ orderSn }}
      </el-form-item>
      <el-form-item label="订单金额：">
        {{ amount }} 元
      </el-form-item>
      <el-form-item label="支付方式：">
        {{ chargeTypeName }}
      </el-form-item>
      <el-form-item label="支付流水号：">
        {{ payOrderNo }}
      </el-form-item>
      <el-form-item label="订单备注：">
        {{ remark }}
      </el-form-item>
      <el-form-item label="审核结果：" prop="auditStatus">
        <el-radio-group v-model="auditForm.auditStatus">
          <el-radio :label="10">通过</el-radio>
          <el-radio :label="11">拒绝</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="审核备注：">
        <el-input v-model="auditForm.auditRemark" :rows="4" type="textarea" placeholder="输入审核备注" />
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="submitLoading" type="primary" @click="auditSubmit">提交</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { auditOrder } from '@/api/audit'

export default {
  // eslint-disable-next-line vue/require-prop-types
  props: {
    orderSn: {
      type: String,
      default: ''
    },
    remark: {
      type: String,
      default: ''
    },
    amount: {
      type: Number,
      default: 0
    },
    chargeTypeName: {
      type: String,
      default: '',
    },
    payOrderNo: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      dialog: false,
      submitLoading: false,
      auditForm: {
        orderSn: null,
        auditStatus: 10,
        auditRemark: ''
      },
      auditRules: {
        auditStatus: [{ required: true, message: '请选择审核状态', trigger: 'blur' }]
      }
    }
  },
  methods: {
    auditSubmit() {
      this.$refs.auditForm.validate((valid) => {
        if (valid) {
          this.submitLoading = true
          this.auditForm.orderSn = this.orderSn
          auditOrder(this.auditForm).then(res => {
            this.$message({
              message: '审核成功',
              type: 'success'
            })
            this.submitLoading = false
            this.dialog = false
            this.$emit('auditSubmit', true)
          }).finally(() => {
            this.submitLoading = false
            this.auditForm.auditStatus = 10
            this.auditForm.auditRemark = ''
          })
        }
      })
    },
    cancel() {
      this.dialog = false
    }
  }
}
</script>

<style lang="scss" scoped>
  .dialog-footer{
    text-align: right
  }
</style>
